package com.backstage.lyorder.controller;


import com.backstage.lyorder.pojo.MobileEndOrder;
import com.backstage.lyorder.pojo.MobileEndOrderevaluation;
import com.backstage.lyorder.pojo.QueryData;
import com.backstage.lyorder.service.MobileEndOrderevaluationService;
import com.backstage.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单评价表 前端控制器
 * </p>
 *
 * @author sakura
 * @since 2022-12-13
 */
@RestController
@RequestMapping("/orderEvaluation")
@CrossOrigin
public class MobileEndOrderevaluationController {

    @Autowired
    private MobileEndOrderevaluationService orderevaluationService;

    /**
     * 查询订单评价表
     * @return
     */
    @PostMapping("list")
    public R getEvalutionList(@RequestBody QueryData queryData){
        Page<MobileEndOrderevaluation> page = new Page<>(queryData.getCp(), queryData.getLs());
        QueryWrapper<MobileEndOrderevaluation> queryWrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(queryData.getOrderIdkw()))
            queryWrapper.eq("orderid",queryData.getOrderIdkw());
        if (!StringUtils.isEmpty(queryData.getNamekw()))
            queryWrapper.eq("name",queryData.getNamekw());
        if (!StringUtils.isEmpty(queryData.getPhonekw()))
            queryWrapper.eq("tel",queryData.getPhonekw());
        queryWrapper.eq("status",queryData.getStatus());
        orderevaluationService.page(page,queryWrapper);
        return R.ok().data("items",page.getRecords()).data("total",page.getTotal()).data("current",page.getCurrent())
                .data("pagesize",page.getSize());
    }


    /**
     * 根据id删除当前评价
     * @param id
     * @return
     */
    @DeleteMapping("remove/{id}")
    public R remove(@PathVariable Long id){
        return orderevaluationService.removeById(id)?R.ok():R.error();
    }

}

